package com.wjy.dao;

import com.wjy.exception.business.BusinessException;
import com.wjy.jdbc.SQLUtil;
import com.wjy.thread.ThreadLocalEnv;
import com.wjy.vo.DesignTemplet;
import lombok.extern.log4j.Log4j2;

import java.util.List;

@Log4j2
public class DesignTempletDao extends SQLUtil {

    public DesignTemplet getDesignTemplet(String designTempletId) throws Exception {

        String sql = "SELECT design_templet.design_templet_id, design_templet.design_templet_name, "
                + "design_templet.finish_time, design_templet.start_recovery_time, design_templet.end_recovery_time, "
                + "design_templet.state, design_templet.link, design_templet.author_id "
                + "FROM design_templet WHERE design_templet.design_templet_id = ? AND design_templet.author_id = ?";

        Object[] objects = new Object[]{designTempletId, ThreadLocalEnv.getENV().getAuthor_id()};

        List<DesignTemplet> designTempletList = Query(sql, objects, DesignTemplet.class);

        if (designTempletList.size() == 0) {

            throw new BusinessException("调查问卷不存在");

        }

        DesignTemplet dt = designTempletList.get(0);

        log.info(dt.toString());

        return dt;

    }

}
